package com.kede.api.stand.schedu;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;
import java.time.LocalDateTime;
import java.util.Date;

/***
 ** @Author:Pr.li
 ** @Description:
 ** @Date: create in 2023/4/28 12:50
 ***/
@Component
@EnableScheduling
@Slf4j
public class DeleteShareImgSchedu {


    /**
     * 存放文件的地址
     * @param key
     * @return
     */
    @Value("${file.location}")
    private String location;

    @Scheduled(cron = "1 13 12 * * *")
    public void deleimg(){
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(location).append("/").append("shareimg");
        DateTime dateTime = DateUtil.offsetDay(new Date(), -1);
        String dirname = DateUtil.format(dateTime, "yyyy-MM-dd");
        stringBuilder.append("/").append(dirname);
        FileUtil.del(stringBuilder.toString());
    }

}
